package beans;

import javax.faces.component.UIViewRoot;
import javax.faces.event.PhaseEvent;
import javax.faces.event.PhaseId;
import javax.faces.event.PhaseListener;

public class LoginListener implements PhaseListener {

	  /**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	@Override
	  public void afterPhase(PhaseEvent event) {
	    System.out.println(">>>> afterPhase: O ID da view é " + 
	            event.getFacesContext().getViewRoot().getViewId() + 
	            " e o ID da fase é " + event.getPhaseId());
	  }

	  @Override
	  public void beforePhase(PhaseEvent event) {
	    
	    UIViewRoot root = event.getFacesContext().getViewRoot();
	    
	    if (root != null) {
	      System.out.println(">>>> beforePhase: O ID da view é " + 
	            root.getViewId() + " e o ID da fase é " + 
	            event.getPhaseId());
	    } else {
	      System.out.println(">>>> beforePhase: A view root ainda é nula");
	    }    
	  }

	  @Override
	  public PhaseId getPhaseId() {
	    return PhaseId.ANY_PHASE;
	  }
	}
